package com.lemon.exam.entity.po;

import com.lemon.exam.common.annotation.LogicDelete;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户表 持久层对象
 *
 * @author Lemon
 * @since 2025/03/24 10:14:39
 */
@Getter
@Setter
@ToString
@Table(value = "sys_user")
@Schema(name = "用户表")
public class UserPO implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @Id
    @Schema(description = "主键ID")
    @Column(value = "id")
    private Long id;

    @Schema(description = "用户名")
    @Column(value = "username")
    @NotBlank(message = "用户名不能为空")
    private String username;

    @Schema(description = "密码")
    @Column(value = "password")
    private String password;

    @Schema(description = "姓名")
    @Column(value = "name")
    @NotBlank(message = "姓名不能为空")
    private String name;

    @Schema(description = "手机号")
    @Column(value = "phone")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式错误")
    private String phone;

    @Schema(description = "性别 1男 2女")
    @Column(value = "sex")
    @NotNull(message = "性别不能为空")
    private Integer sex;

    @Schema(description = "邮箱")
    @Column(value = "email")
    @Email(message = "邮箱格式不正确")
    private String email;

    @Schema(description = "生日")
    @Column(value = "birthday")
    @NotNull(message = "生日不能为空")
    private LocalDate birthday;

    @Schema(description = "头像地址")
    @Column(value = "avatar")
    private String avatar;

    @Schema(description = "省ID")
    @Column(value = "province_id")
    @NotNull(message = "请选择省份")
    private Integer provinceId;

    @Schema(description = "市ID")
    @Column(value = "city_id")
    @NotNull(message = "请选择城市")
    private Integer cityId;

    @Schema(description = "县ID")
    @Column(value = "county_id")
    @NotNull(message = "请选择县区")
    private Integer countyId;

    @Schema(description = "地址")
    @Column(value = "address")
    @NotBlank(message = "地址不能为空")
    private String address;

    @Schema(description = "上次登录的IP")
    @Column(value = "prev_login_ip")
    private String prevLoginIp;

    @Schema(description = "上次登录的时间")
    @Column(value = "prev_login_time")
    private String prevLoginTime;

    @Schema(description = "创建人")
    @Column(value = "create_by")
    private String createBy;

    @Schema(description = "创建时间")
    @Column(value = "create_time")
    private LocalDateTime createTime;

    @Schema(description = "修改人")
    @Column(value = "update_by")
    private String updateBy;

    @Schema(description = "修改时间")
    @Column(value = "update_time")
    private LocalDateTime updateTime;

    @Schema(description = "状态 1正常 0异常")
    @Column(value = "status")
    private Integer status;

    @Schema(description = "删除状态 1是 0否")
    @Column(value = "deleted")
    @LogicDelete
    private Integer deleted;

    @Transient
    @Schema(description = "角色ID集合")
    @NotNull(message = "请选择角色")
    @Size(min = 1, message = "请选择用户")
    private List<Long> roleIdList;

    @Transient
    @Schema(description = "班级职位ID集合")
    @Size(min = 1, message = "请选择班级&职位")
    private List<List<Long>> gradeClassJobIdList;
}
